//
//  GYAppVersionView.m
//  GoodLuck
//
//  Created by apple on 2018/5/14.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

static NSString *appVersionCellIdentifier = @"appVersionCellIdentifier";

#import "GYAppVersionView.h"

@interface GYAppVersionView ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableviewHeightCons;
@property (weak, nonatomic) IBOutlet UIButton *updateBtu;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headImageviewHeightCons;

@end
@implementation GYAppVersionView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.updateBtu.layer.cornerRadius = 4;
    self.tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableview.rowHeight = 25;
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:appVersionCellIdentifier];
}

- (void)setBugContents:(NSArray *)bugContents {
    _bugContents = bugContents;
    
    //计算tablView的高度
    self.tableviewHeightCons.constant = 25*(bugContents.count>5 ? 5 : bugContents.count);
    
    [self.tableview reloadData];
}
- (CGFloat)getHeight:(NSArray *)source {
    self.bugContents = source;
    
    [self layoutIfNeeded];
    
    return CGRectGetMaxY(self.updateBtu.frame)+ 10;
}

- (IBAction)updateAppVersionBtuClick:(UIButton *)sender {
    NSLog(@"APP更新按钮点击事件.....");
    self.appUpdateCallBack();
    
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.bugContents.count > 5 ? 5 : self.bugContents.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:appVersionCellIdentifier];
    cell.textLabel.text = self.bugContents[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:14];

    return cell;
}
@end
